package thread;

public class SyncDemo {
    private static boolean success1=false;
    private static boolean success2 = false;

    public static void main(String[] args) {
        Bank bank = new Bank();
        int num=0;
        while(true){
        Thread t1 = new Thread() {
        public   void run(){
            success1 = bank.getMoney(2000);
        }
        };

        Thread t2=new Thread(){
            public void run(){
                success2 = bank.getMoney(2000);
            }
        };

        t1.start();
        t2.start();



        if(success1&&success2){
            System.out.println("全部取款成功，出现了并发安全问题!");
            num++;
            success1=false;
            success2=false;
        }

        else{
            num++;
            System.out.println("只有一人取款成功");
            bank.saveAccount(2000);
            System.out.println("第"+num+"次尝试");


            break;

        }

    }
}}
